package com.ruoyi.project.video.chatrooms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.video.chatrooms.domain.Chatrooms;
import com.ruoyi.project.video.chatrooms.service.IChatroomsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 聊天室Controller
 * 
 * @author ruoyi
 * @date 2024-11-25
 */
@Controller
@RequestMapping("/video/chatrooms")
public class ChatroomsController extends BaseController
{
    private String prefix = "video/chatrooms";

    @Autowired
    private IChatroomsService chatroomsService;

    @RequiresPermissions("video:chatrooms:view")
    @GetMapping()
    public String chatrooms()
    {
        return prefix + "/chatrooms";
    }

    /**
     * 查询聊天室列表
     */
    @RequiresPermissions("video:chatrooms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Chatrooms chatrooms)
    {
        startPage();
        List<Chatrooms> list = chatroomsService.selectChatroomsList(chatrooms);
        return getDataTable(list);
    }

    /**
     * 导出聊天室列表
     */
    @RequiresPermissions("video:chatrooms:export")
    @Log(title = "聊天室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Chatrooms chatrooms)
    {
        List<Chatrooms> list = chatroomsService.selectChatroomsList(chatrooms);
        ExcelUtil<Chatrooms> util = new ExcelUtil<Chatrooms>(Chatrooms.class);
        return util.exportExcel(list, "聊天室数据");
    }

    /**
     * 新增聊天室
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存聊天室
     */
    @RequiresPermissions("video:chatrooms:add")
    @Log(title = "聊天室", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Chatrooms chatrooms)
    {
        return toAjax(chatroomsService.insertChatrooms(chatrooms));
    }

    /**
     * 修改聊天室
     */
    @RequiresPermissions("video:chatrooms:edit")
    @GetMapping("/edit/{ChatRoomID}")
    public String edit(@PathVariable("ChatRoomID") Long ChatRoomID, ModelMap mmap)
    {
        Chatrooms chatrooms = chatroomsService.selectChatroomsByChatRoomID(ChatRoomID);
        mmap.put("chatrooms", chatrooms);
        return prefix + "/edit";
    }

    /**
     * 修改保存聊天室
     */
    @RequiresPermissions("video:chatrooms:edit")
    @Log(title = "聊天室", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Chatrooms chatrooms)
    {
        return toAjax(chatroomsService.updateChatrooms(chatrooms));
    }

    /**
     * 删除聊天室
     */
    @RequiresPermissions("video:chatrooms:remove")
    @Log(title = "聊天室", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chatroomsService.deleteChatroomsByChatRoomIDs(ids));
    }
}
